<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title></title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../../../lib/layui-v2.6.3/css/layui.css" media="all">
  <link rel="stylesheet" href="../../../css/public.css" media="all">
  <style>
      body {
          background-color: #ffffff;
      }
  </style>
</head>
<body>
<div class="layui-form layuimini-form" id="myForm">
  <div class="layui-form-item">
    <label class="layui-form-label required">组织名称</label>
    <div class="layui-input-block">
      <input type="text" name="orgName" lay-verify="required" placeholder="请输入" value="" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">负责人姓名</label>
    <div class="layui-input-block">
      <input type="text" name="personCharge" placeholder="请输入" value="" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">联系电话</label>
    <div class="layui-input-block">
      <input type="text" name="tel" placeholder="请输入" value="" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">是否作为栏目</label>
    <div class="layui-input-block">
      <input type="checkbox" name="navFlag" lay-skin="switch" lay-filter="navFlag" lay-text="是|否">
    </div>
  </div>

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">添加</button>
    </div>
  </div>
</div>

<script src="../../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../../lib/jsencrypt/jsencrypt.js" charset="utf-8"></script>
<script src="../../../api/common.js" charset="utf-8"></script>
<script>
  layui.use(['form'], function () {
    var form = layui.form,
      layer = layui.layer,
      $ = layui.$;

    //监听提交
    form.on('submit(saveBtn)', function (data) {
      var obj = data.field
      if(obj.navFlag){
        obj.navFlag = true
      }else{
        obj.navFlag = false
      }
      $.ajax({
        type: 'POST',
        url: local + 'org/add',
        data: JSON.stringify(obj),
        dataType: "json",
        headers: {
          'Authorization': `Bearer ${ localStorage.getItem("token") }`,
        },
        contentType: 'application/json;charset=UTF-8',
        success: function (res) {//res为相应体,function为回调函数
          console.log('data', res)
          if (res.code === 200) {
            // layer.alert('添加成功');
            var iframeIndex = parent.layer.getFrameIndex(window.name);
            parent.layer.close(iframeIndex);
            parent.layui.table.reload('currentTableId');
            return false;
          }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          layer.alert('操作失败！！！' + XMLHttpRequest.status + "|" + XMLHttpRequest.readyState + "|" + textStatus, {icon: 5});
        }
      });
    });
  });
</script>
</body>
</html>
